package com.shuai.shuaisecondhand_springboot.mapper;

import com.shuai.shuaisecondhand_springboot.entity.Leave;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LeaveMapper {

    //sql->插入
    @Insert("INSERT INTO `leave`(Uid,Gid,message) VALUES (#{Uid},#{Gid},#{message})")
    Boolean insertLeave(@Param("Uid") String Uid,@Param("Gid") String Gid,@Param("message") String message);

    //sql->删除
    @Delete("DELETE FROM `leave` WHERE id=#{id} AND Uid=#{Uid}")
    Integer deleteLeave(@Param("id") long id,@Param("Uid") long Uid);

    //sql->根据Gid查询数据
    //sql->商品留言分页查询
    @Select("SELECT *  FROM `leave` LEFT JOIN user ON `leave`.Uid=user.id  WHERE `leave`.Gid=#{Gid}  limit #{pageNum}, #{pageSize} ")
    List<Leave> getLeavePage(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize, @Param("Gid") String Gid);

    //sql->查询Gid所有数据量
    @Select("SELECT count(*) FROM `leave` WHERE Gid=#{Gid} ")
    int getGidTotal(@Param("Gid") String Gid);


    //sql->根据Sid查询数据
    //sql->商品留言分页查询
    @Select("SELECT *  FROM `leave` LEFT JOIN user ON `leave`.Uid=user.id  WHERE `leave`.Uid=#{Uid}  limit #{pageNum}, #{pageSize} ")
    List<Leave> getLeavePageUid(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize, @Param("Uid") String Uid);

    //sql->查询Gid所有数据量
    @Select("SELECT count(*) FROM `leave` WHERE Uid=#{Uid} ")
    int getUidTotal(@Param("Uid") String Uid);
}
